package org.xyl.game.service.impl;

import com.google.common.util.concurrent.AbstractListeningExecutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xyl.game.dao.MapregistrantDao;
import org.xyl.game.dao.MaproomDao;
import org.xyl.game.entity.Mapregistrant;
import org.xyl.game.entity.Maproom;
import org.xyl.game.service.MapgameService;

@Service
public class MapgameServiceImpl implements MapgameService {
    @Autowired
    private MaproomDao maproomDao;
    @Autowired
    private MapregistrantDao mapregistrantDao;

    @Transactional
    @Override
    public boolean signMap(int id, String username, int block) {
        Mapregistrant byUsernameAndMaproomid = mapregistrantDao.findByUsernameAndMaproomid(username, id);
        if (byUsernameAndMaproomid != null) {
            return false;
        }
        Maproom byId = maproomDao.getById(id);
        switch (block) {
            case 1:
                byId.setBlock1(byId.getBlock1() + 1);
                break;
            case 2:
                byId.setBlock2(byId.getBlock2() + 1);
                break;
            case 3:
                byId.setBlock3(byId.getBlock3() + 1);
                break;
            case 4:
                byId.setBlock4(byId.getBlock4() + 1);
                break;
            case 5:
                byId.setBlock5(byId.getBlock5() + 1);
                break;
            case 6:
                byId.setBlock6(byId.getBlock6() + 1);
                break;
            case 7:
                byId.setBlock7(byId.getBlock7() + 1);
                break;
            case 8:
                byId.setBlock8(byId.getBlock8() + 1);
                break;
            case 9:
                byId.setBlock9(byId.getBlock9() + 1);
                break;

        }
        maproomDao.save(byId);
        Mapregistrant mapregistrant = new Mapregistrant();
        mapregistrant.setMaproomid(id);
        mapregistrant.setUsername(username);
        mapregistrantDao.save(mapregistrant);
        return true;

    }

}
